import { http } from '@/utils/http'
import { LoginParams, UserInfo } from './type'
// 手机号码登录
export const fetchLogin = (params: LoginParams) =>
  http.post<UserInfo & { token: string }>('/shopapi/login/account', params)

export const fetchAuthLogin = <D>(params: D) =>
  http.post<UserInfo & { token: string }>('/shopapi/login/silentLogin', params)

export const fetchOpenid = <D>(params: D) => http.post<any>('/shopapi/login/getOpenid', params)

// 手机快捷登录
export const fetchQuickLogin = <D>(params: D) =>
  http.post<UserInfo & { token: string }>('/shopapi/login/quickLogin', params)

// 获取用户信息
export const fetchUserInfo = () => http.post<UserInfo>('/shopapi/user/info')

export const fetchUpdateUserInfo = <D>(data: D) =>
  http.post<UserInfo>('/shopapi/user/setInfo', data)

export const fetchUpdateProfile = <D>(data: D) =>
  http.post<UserInfo>('/shopapi/user/setProfile', data)

// 签到
export const signAction = () => http.post('/shopapi/sign/sign')

// 申请分销
export const applyDistribution = <D>(data: D) => http.post('/shopapi/distribution/apply', data)

// 我的团队
export const fetchTeamList = (params: Pagination & { type: string }) =>
  http.get('/shopapi/distribution/fans', params)

// 签到规则
export const fetchSignRules = () => http.get('/shopapi/sign/lists')

// 打卡管理
export const fetchClockRules = () => http.get<any>('/shopapi/signKnow/lists')

// 打卡规则
export const fetchClockRule = () => http.get<any>('/shopapi/signKnow/getRemark')

// 打卡
export const fetchClock = () => http.post('/shopapi/signKnow/sign')

// 绑定上级
export const bindSuperiors = <D>(data: D) => http.post('/shopapi/distribution/code', data)

// 积分明细 和 佣金明细
export const fetchIntegralDetails = (p: Pagination & { type: string }) =>
  http.get('/shopapi/account_log/lists', p)

// 优惠券
export const fetchCouponList = (p: Pagination & { status: string }) =>
  http.get('/shopapi/coupon/my', p)

// 浏览记录
export const fetchHistory = (p: Pagination) => http.get('/shopapi/goodsVisit/lists', p)

// 会员等级
export const fetchLevelList = () => http.get('/shopapi/user/userLevelList')

// 收藏列表
export const fetchCollectList = (p: Pagination & { type: string }) => {
  const apis = {
    1: '/shopapi/collect/lists',
    2: '/shopapi/collect/articleLists',
  }
  const { type, ...params } = p
  return http.get(apis[type], params)
}
